package com.gebiafu.mapper;

import com.gebiafu.pojo.SystemFile;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * title: SystemFileMapper
 * author: Gebiafu
 * date: 2021/07/02 17:19
 */
@Mapper
public interface SystemFileMapper {
    /**
     * 上传文件信息添加到数据库
     * @param systemFile
     * @return
     */
    @Insert("insert into f_file(id,file_name,original_file_name,file_size,user_id) "+
            "values(#{id},#{filename},#{originalFileName},#{fileSize},#{userId})")
    int insert(SystemFile systemFile);

    /**
     * 基于PageHelper实现分页
     * 分页查询文件
     * 查询条件是登陆用户的主键,和分页逻辑
     * @param userId
     * @return
     */
    @Select("select id,file_name as fileName,original_file_name as originalFileName, "+
            "file_size as fileSize,user_id as userId "+
            "from f_file where user_id=#{userId}")
    List<SystemFile> selectByUserId(Long userId);
}
